<!--edit page create by pionner at Tue Nov 25 15:11:25 CST 2008-->
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@taglib uri="ttp://www.security.com/tag" prefix="sc"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script language="javascript">
function IsEmpty()
{
var userName=document.addform.userName.value;
var userPwd=document.addform.userPwd.value;
var birthday=document.addform.birthday.value;
if(userName==0||userPwd==0||birthday==0){
alert("请填写完整内容！");
return;
}
if(!isDate(birthday)){
alert("请输入YYYY-MM-DD格式的生日");
return;
}
document.addform.submit();
}

 function   isDate(str){   
  if(!str.match(/^\d{4}\-\d\d?\-\d\d?$/)){return   false;}   
  var   ar=str.replace(/\-0/g,"-").split("-");   
  ar=new   Array(parseInt(ar[0]),parseInt(ar[1])-1,parseInt(ar[2]));   
  var   d=new   Date(ar[0],ar[1],ar[2]);   
  return   d.getFullYear()==ar[0] &&   d.getMonth()==ar[1]   &&   d.getDate()==ar[2];   
  }   

</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	<base href="<%=basePath%>">
		<title></title>
		<link rel="stylesheet" href="css/style.css">
		<link rel='stylesheet' type='text/css' href='css/table.css'>
		<link rel='stylesheet' type='text/css' href='css/style.css'>
		<link href="template/css.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" type="text/css" media="all" href="<%=path%>/js/calendar/calendar-win2k-cold-1.css" title="win2k-cold-1" />
	    <script type="text/javascript" src="<%=path%>/js/calendar/calendar.js"></script>
		<script type="text/javascript" src="<%=path%>/js/calendar/calendar-setup.js"></script>
		<script type="text/javascript" src="<%=path%>/js/calendar/calendar-zh1.js"></script> 
		<script src='js/prototype-1.4.0.js'></script>
		<script src='js/comm.js'></script>
	</head>
	<body>
		
		<table width="200" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="90"><img src="images/loc-head.jpg" width="90" height="24"></td>
				<td valign="middle" nowrap background="images/loc-bg.jpg">用户新增</td>
				<td width="12"><img src="images/loc-tail.jpg" width="12" height="24"></td>
			</tr>
		</table><br>		
		<s:form name="addform"  action="userlistSave.action">
			<table width='100%' border='0' cellspacing='1' class="ipttable">
				<s:hidden name="rtPage" value="fylist"/>
				<s:textfield cssClass="input130" onkeyup="keypress();"  id="code" name='code' label='编号'/>
				<s:textfield cssClass="input130" name='userName' label='用户拼音'/>
				<s:textfield cssClass="input130" name='cname' label='中文姓名'/>
				<tr><td><label class="label">性别：</label></td><td>
					<select name="agender">
						<option value="男" selected>男</option>
						<option value="女">女</option>
					</select>
				</td></tr>
<tr><td><label class="label">人员性质:</label></td><td>
					<select name="kind">
						<option value="固定">固定</option>
						<option value="流动">流动</option>
					</select>
				</td></tr>
				<s:textfield cssClass="input130" name='birthday' label='生日（例：1980-01-01）'/>
				<s:hidden cssClass="input130" name='userId' label='身份证'/>
				<s:password cssClass="input130" name='userPwd' label='密码' size="22"/>				
				<s:textfield cssClass="input130" name='telphone' label='手机号码'/>				
				<s:hidden id="departmentId" name='departmentId'/>
				<s:textfield cssClass="input130" onclick="openform()" id="departmentName" name='departmentName' label='部门'/>
			
				<s:textarea cssClass="textarea" name='address' label='地址'></s:textarea>
			</table>
			<table width='50%' border='0' cellspacing='0' >
			<tr>
			<td align="center">
			<input type="button" value="提交" onClick="javascript:IsEmpty()" class="submitbtn">
			<input type="reset" value="重置" class="resetbtn">
			<input type="button" value="返回" onClick="javascript:history.back(-1)" class="backbtn">
			</td>
			</tr>
			</table>
		</s:form>
	</body>
</html>
<script type="text/javascript">
Calendar.setup(
		    {
		      inputField  : 'userlistSave.action_birthday',         // ID of the input field
		      ifFormat    : "%Y-%m-%d",    // the date format
		     // onSelect   : onSelect,
		      showsTime : false
		    }
		  );
	function keypress(){
		var intKey  =  event.keyCode;
		if(13==intKey || document.all.code.value.length>4){
			getCode();
		}
		
	}
	function getCode(){
		var url="usermaxcode.action?prex="+encodeURIComponent(document.all.code.value);
		 var myAjax = new Ajax.Request(
					url, 
					{ 
						method: 'post', 
						asynchronous:false
					
				}); 
		var mycode = myAjax.transport.responseText;
		
		if(0==mycode){
			document.all.code.value+='0001'
			return false;
		}
		
		var numstr=mycode.substr(5,4);
		numstr++;
		
		var numint=parseInt(numstr);
		
		//numint++;
		var prefstr=mycode.substr(0,5);
		//alert(prefstr+"  +  "+numstr);
		numstr=numint+"";
		numstr=to4Long(numstr);
		
		document.all.code.value=prefstr+numstr;
	}
	
	function to4Long(num){
		var l=num.length;
		var addl=4-l;
		
		var rt="";
		if(addl>0){
			for(var i=0;i<addl;i++){
				rt+="0";
			}
			
		}
		
		return rt+""+num;
	}
    	function openform(){
    		var title = ""; 
		var url = '../deptSel.jsp';
		var pageUrl="../deptSel.jsp";
		var paraObj = new Object();
		paraObj.url=url;
		paraObj.title=title;
		paraObj.rootId='-2';
		var objId=document.getElementById("departmentId");
		var objName=document.getElementById("departmentName");
		paraObj.input=objId;
		var sFeatures = 'help:no;status:1;dialogHeight:500px;dialogWidth:350px;center:1';
	    var rtnObj= window.showModalDialog(pageUrl,paraObj,sFeatures );
	    //alert('rtnObj='+rtnObj);
		if(rtnObj){
			var result=rtnObj.result;
			objId.value=result.id;
			objName.value=result.name;
		}else{
    		
    	}
    	//alert('openform');
    	}
    </script>

